﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TrainGame.Engine;

namespace UnitTests.Common
{
	/// <summary>
	/// tests for GameEngine.CalculateHexDistance
	/// </summary>
	[TestClass]
	public class HexDistanceTests
	{
		[TestMethod]
		public void HexDistance_OutOfBOunds()
		{
			Test(99, "A", "B");
		}

		[TestMethod]
		[ExpectedException (typeof (FormatException))]
		public void HexDistance_Exception()
		{
			Test(99, "Az", "B10");
		}

		[TestMethod]
		public void HexDistance_SameColumn()
		{
			Test(2, "B11", "B15");
			Test(3, "G20", "G14");
			Test(4, "N1", "N9");
		}

		[TestMethod]
		public void HexDistance_OneColumnDifference()
		{
			Test(2, "B11", "C14");
			Test(4, "G20", "F13");
			Test(5, "N1", "M10");
		}

		[TestMethod]
		public void HexDistance_TwoColumnDifference()
		{
			Test(3, "E10", "C14");
			Test(5, "H21", "F13");
			Test(5, "O2", "M10");
		}

		[TestMethod]
		public void HexDistance_SameRow()
		{
			Test(5, "B10", "G10");
			Test(6, "C14", "I14");
		}

		[TestMethod]
		public void HexDistance_OneRowDifference()
		{
			Test(5, "B10", "G11");
			Test(6, "C14", "I13");
		}

		[TestMethod]
		public void HexDistance_TwoRowDifference()
		{
			Test(5, "B8", "G10");
			Test(6, "C16", "I14");
		}

		[TestMethod]
		public void HexDistance_SameHex()
		{
			Test(0, "B10", "B10");
			Test(0, "M1", "M1");
		}

		[TestMethod]
		public void HexDistance_SameDiagonal()
		{
			Test(11, "C18", "N7");
			Test(8, "F9", "N17");
		}

		[TestMethod]
		public void HexDistance_Far()
		{
			Test(13, "A16", "N11");
			Test(10, "H5", "N19");
		}

		static private void Test (int distance, string hex1, string hex2)
		{
			// do it both orders to make sure the same result
			Assert.AreEqual(distance, GameEngine.CalculateHexDistance(hex1, hex2),
				string.Format("Distance between {0} and {1}", hex1, hex2));

			Assert.AreEqual(distance, GameEngine.CalculateHexDistance(hex2, hex1),
				string.Format("Reverse Distance between {0} and {1}", hex2, hex1));
		}
	}
}
